In [2]:
% matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
import plotly.plotly as py
The PMF for Bernoulli is
bernoulli.pmf(k) = 1 - p, if k = 0
= p, if k = 1
In [ ]:
from scipy.stats import bernoulli
In [9]:
p = 0.3 # probability
# plotting the bernoulli
fig, ax = plt.subplots(1, 1)
x = np.arange(bernoulli.ppf(0.01, p),
bernoulli.ppf(0.99, p))
ax.plot(x, bernoulli.pmf(x, p), 'bo', ms=8, label='bernoulli pmf')
ax.vlines(x, 0, bernoulli.pmf(x, p), colors='b', lw=5, alpha=0.5)
py.iplot_mpl(fig)
Out[9]: